package com.sjh.test.java8.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class LambdaFunctionDemo {

    public static void main(String[] args)
    {
        LambdaFunctionDemo tester = new LambdaFunctionDemo();
        tester.run();
    }

    public void run()
    {
        List<Student> list = new ArrayList<Student>();

        list.add(new LambdaFunctionDemo.Student("Redis",20));
        list.add(new LambdaFunctionDemo.Student("Shuffer",22));
        list.add(new LambdaFunctionDemo.Student("Kafla",18));
        for(Student st: list){
            System.out.println(st.customShow(s->s.getName()+": "+s.getAge()));
        }
    }

    public class Student
    {
        private String name;
        private int age;
        public Student(String name,int age){
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public  String customShow(Function<Student,String> fun){
            return fun.apply(this);
        }
    }
}
